/**
 * 
 * SearchResult.java
 * Defender
 * 2013-11-23
 */
package com.ls.fw.data.search.impl.lucene.bean;

import java.io.IOException;

import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TopDocs;

/**
 * 索引查询结果
 * com.demo.lucene.bean SearchResult
 * @author Defender
 * 2013-11-23 下午09:31:41
 */
public class SearchResult {
	
	
	private TopDocs topdocs = null;
	
	private IndexSearcher searcher = null;
	
	private long numDocs = 0;
	private long maxDocs = 0;
	private long deleteDocs = 0;
	
	/**
	 * 使用完后，注意关闭
	 * @param topdocs
	 * @param searcher 
	 */
	public SearchResult(TopDocs topdocs, IndexSearcher searcher) {
		super();
		this.topdocs = topdocs;
		this.searcher = searcher;
		this.numDocs = searcher.getIndexReader().numDocs();
		this.maxDocs = searcher.getIndexReader().maxDoc();
		this.deleteDocs = searcher.getIndexReader().numDeletedDocs();
	}
	
	
	
   public SearchResult(TopDocs topdocs, IndexSearcher searcher, long numDocs,
			long maxDocs, long deleteDocs) {
		super();
		this.topdocs = topdocs;
		this.searcher = searcher;
		this.numDocs = numDocs;
		this.maxDocs = maxDocs;
		this.deleteDocs = deleteDocs;
	}



/**
    * 关闭读入器 
    * Defender
    * 2013-11-23 下午09:38:27
    */
	public void close(){
		try {
			this.searcher.getIndexReader().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * @return the topdocs
	 */
	public TopDocs getTopdocs() {
		return this.topdocs;
	}
	/**
	 * @param topdocs the topdocs to set
	 */
	public void setTopdocs(TopDocs topdocs) {
		this.topdocs = topdocs;
	}
	/**
	 * @return the searcher
	 */
	public IndexSearcher getSearcher() {
		return this.searcher;
	}
	/**
	 * @param searcher the searcher to set
	 */
	public void setSearcher(IndexSearcher searcher) {
		this.searcher = searcher;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("SearchResult [topdocs=");
		builder.append(this.topdocs);
		builder.append(", searcher=");
		builder.append(this.searcher);
		builder.append(", numDocs=");
		builder.append(this.numDocs);
		builder.append(", maxDocs=");
		builder.append(this.maxDocs);
		builder.append(", deleteDocs=");
		builder.append(this.deleteDocs);
		builder.append("]");
		return builder.toString();
	}
	
	
}
